﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class BCell : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
    //抗体
    public GameObject antibody;
    //生成数量范围
    public float min_Anti;
    public float max_Anti;
    //最大周期
    public float max_Interval;
    //生成周期
    public float g_Interval;
    private Cell m_Cell;
    private UnityAction m_Action;
    private int m_CurrentIntervals;
    private void Awake()
    {
        m_Action += Tick;
        m_Cell = GetComponent<Cell>();
        GameController.Instance.AddTickEvent(m_Action);
    }
    // Update is called once per frame
    void Update () {
        m_Cell.Wander();
    }
    private void Tick()
    {
      //  Debug.Log("fuck");
        // float CurrentInterval = GameController.Instance.CurrentInterval;
        m_CurrentIntervals++;
        // Debug.Log();
        //周期等于3
        if (m_CurrentIntervals> max_Interval) {
            //移动
            GameController.Instance.RemoveTickEvent(m_Action);
            Destroy(this.gameObject);
        }
        else
        if (m_CurrentIntervals % g_Interval == 0)
        {
            // Debug.Log("fuck"+ m_CurrentIntervals);
            generate();
        }
    }
    private void generate()
    {
        float rom = Random.Range(min_Anti, max_Anti);
        for (int i=0;i<rom;i++)
        {
            Instantiate(antibody, transform.position, Quaternion.identity);
        }
    }
}
